﻿/*    
Nemulation: A .NET based framework/platform for virtualization applications
Copyright (C) 2011 Bryan Perris

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NEmu;

namespace NEmu.TestUnits
{
    [TestFixture, Description("Tests different run modes of VirtualMachine class")]
    public sealed class TestMachineA : VirtualMachine
    {
        bool testboot = false;
        bool init = false;
        TestResourceManger m_Resources;
        TestMemory m_Memory;

        public TestMachineA()
        {
            m_Memory = new TestMemory(this);
            m_Resources = new TestResourceManger(this);
        }

        protected override void Boot()
        {
            testboot = true;
        }

        protected override void InitializeComponents()
        {
            init = true;
        }

        protected override void ShutdownComponents()
        {
            testboot = false;
            init = false;
        }

        public override ResourceManager Resources
        {
            get { return m_Resources; }
        }

        public override Memory.MemoryUnit MachineMemory
        {
            get { return m_Memory; }
        }

        #region Tests

        [Test, Description("Tests boot up sequence")]
        public void Test_Bootup()
        {
            this.Run();
            Assert.AreNotEqual(false, testboot, "Machine didn't boot");
            this.Stop();
        }

        [Test, Description("Tests pause and resume mode")]
        public void Test_PauseResume()
        {
            this.Run();
            this.Pause();
            Assert.AreEqual(RunState.Paused, this.CurrentRunState, "Current machine state is not on Pause");
            this.Run();
            Assert.AreEqual(RunState.Running, this.CurrentRunState, "Current machine state is not on Run");
            this.Stop();
        }

        [Test, Description("Tests the machine has stopped and of OnStateChanged was called")]
        public void Test_Stop()
        {
            Run();
            Stop();
            Assert.AreEqual(RunState.Stopped, CurrentRunState, "State is not on stop");
            Assert.AreEqual(false, testboot, "booted still true");
        }

        [Test, Description("Tests different states without any problems or crashing of the class")]
        public void Test_StateTest()
        {
            Run();
            Pause();
            Stop();
            Run();
            Stop();
            Pause();
            Assert.AreEqual(RunState.Stopped, CurrentRunState);
        }

        [Test, Description("Tests if InitializeComponents is called")]
        public void Test_InitComponents()
        {
            Run();
            Assert.AreEqual(true, init);
            Stop();
        }

        #endregion
    }
}
